home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / blt / convert.asm < prev    next >
Encoding:
Assembly Source File  |  1993-09-02  |  9.3 KB  |  487 lines

  1. page    ,132
  2. ;----------------------------Module-Header------------------------------;
  3. ; Module Name: SETDI8.ASM
  4. ;
  5. ; move bits from one DIB format into another. doing color conversion if
  6. ; needed.
  7. ;
  8. ;   convert_8_8
  9. ;   convert_16_8
  10. ;   convert_24_8
  11. ;   convert_32_8
  12. ;   copy_8_8
  13. ;   dither_8_8
  14. ;
  15. ; NOTES:
  16. ;
  17. ;  dither needs to work!
  18. ;
  19. ;  AUTHOR: ToddLa (Todd Laney) Microsoft
  20. ;
  21. ;-----------------------------------------------------------------------;
  22. ?PLM=1
  23. ?WIN=0
  24.     .xlist
  25.     include cmacro32.inc
  26.     include windows.inc
  27.     .list
  28.  
  29. sBegin    Data
  30. sEnd    Data
  31.  
  32. ifndef SEGNAME
  33.     SEGNAME equ <_TEXT32>
  34. endif
  35.  
  36. createSeg %SEGNAME, CodeSeg, word, public, CODE
  37.  
  38. sBegin    CodeSeg
  39.     .386
  40.     assumes cs,CodeSeg
  41.     assumes ds,nothing
  42.     assumes es,nothing
  43.  
  44. ;--------------------------------------------------------------------------;
  45. ;--------------------------------------------------------------------------;
  46.  
  47. nxtscan macro reg, next_scan, fill_bytes
  48. ifb <fill_bytes>
  49.     add    e®,next_scan
  50. else
  51.     mov    eax,e®
  52.     add    e®,next_scan
  53.     cmp    ax,reg
  54.     sbb    eax,eax
  55.     and    eax,fill_bytes
  56.     add    e®,eax
  57. endif
  58.     endm
  59.  
  60. NEWCODE equ 1
  61.     
  62. if NEWCODE
  63.  
  64. ;--------------------------------------------------------------------------;
  65. ;
  66. ;   convert_8_8
  67. ;
  68. ;--------------------------------------------------------------------------;
  69.     assumes ds,nothing
  70.     assumes es,nothing      
  71.  
  72. cProc    convert_8_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  73.     ParmD    dst_ptr         ; --> dst.
  74.     ParmD    dst_offset        ; offset to start at.  > 64k
  75.     ParmD    dst_next_scan        ; dst_next_scan.   < 64k signed 
  76.     ParmD    src_ptr         ; --> src.
  77.     ParmD    src_offset        ; offset to start at  > 64k
  78.     ParmD    src_next_scan        ; dst_next_scan.  < 64k signed 
  79.     ParmD    pel_count        ; pixel count.  < 64k unsigned 
  80.     ParmD    scan_count        ; scan count. < 64k unsigned
  81.     ParmD    xlat_table        ; pixel convert table.   ds:0
  82. cBegin
  83.         xor     esi,esi
  84.         xor     edi,edi
  85.         xor     ebx,ebx
  86.         xor    edx,edx
  87.         lfs     si,src_ptr
  88.         les     di,dst_ptr
  89.         lds     bx,xlat_table
  90.  
  91.         add     esi,src_offset
  92.         add     edi,dst_offset
  93.  
  94.         mov     eax,pel_count
  95.         sub     src_next_scan,eax
  96.         sub     dst_next_scan,eax
  97.  
  98.     xor    ebx,ebx
  99. align 4
  100. convert_8_8_start:
  101.  
  102.     mov    ecx,pel_count
  103.     shr    ecx,2
  104.     jz    short convert_8_8_ack
  105.  
  106.     shr    ecx,1
  107.     jc    fixup_for_halfway
  108.  
  109. align 4
  110. convert_8_8_loop:
  111.  
  112.     mov    eax,fs:[esi]        ; grab 4 pixels
  113.  
  114.     mov    bl,al            ; get pel
  115.     mov    dl,ah            ; get pel
  116.     mov    al,[ebx]        ; translate pel
  117.     mov    ah,[edx]        ; translate pel
  118.  
  119.     rol    eax,16
  120.  
  121.     mov    bl,al            ; get pel
  122.     mov    dl,ah            ; get pel
  123.     mov    al,[ebx]        ; translate pel
  124.     mov    ah,[edx]        ; translate pel
  125.  
  126.     rol    eax,16
  127.  
  128.     mov    es:[edi],eax        ; store four
  129.  
  130. half_way:
  131.     mov    eax,fs:[esi+4]        ; grab 4 pixels
  132.  
  133.     mov    bl,al            ; get pel
  134.     mov    dl,ah            ; get pel
  135.     mov    al,[ebx]        ; translate pel
  136.     mov    ah,[edx]        ; translate pel
  137.  
  138.     rol    eax,16
  139.  
  140.     mov    bl,al            ; get pel
  141.     mov    dl,ah            ; get pel
  142.     mov    al,[ebx]        ; translate pel
  143.     mov    ah,[edx]        ; translate pel
  144.  
  145.     rol    eax,16
  146.  
  147.     mov    es:[edi+4],eax        ; store four
  148.  
  149.     add    esi,8
  150.     add    edi,8
  151.  
  152.     dec    ecx
  153.     jnz    short convert_8_8_loop
  154.  
  155. convert_8_8_ack:
  156.     mov    ecx,pel_count
  157.     and    ecx,3
  158.     jnz    short convert_8_8_odd
  159.  
  160. convert_8_8_next:
  161.     nxtscan si,src_next_scan
  162.     nxtscan di,dst_next_scan
  163.  
  164.     dec    scan_count
  165.     jnz    short convert_8_8_start
  166. cEnd
  167.  
  168. fixup_for_halfway:
  169.     sub    edi,4
  170.     sub    esi,4
  171.     jmp    half_way
  172.  
  173. convert_8_8_odd:
  174. @@:    mov    bl,fs:[esi]
  175.     mov    bl,[ebx]
  176.     mov    es:[edi],bl
  177.     inc    esi
  178.     inc    edi
  179.     dec    ecx
  180.     jnz    short convert_8_8_odd
  181.     jz    short convert_8_8_next
  182.  
  183. else
  184. ;--------------------------------------------------------------------------;
  185. ;
  186. ;   convert_8_8
  187. ;
  188. ;--------------------------------------------------------------------------;
  189.         assumes ds,nothing
  190.         assumes es,nothing        
  191.  
  192. cProc   convert_8_8,<FAR,PUBLIC,PASCAL>,<esi,edi,ds>
  193.         ParmD   dst_ptr             ; --> dst.
  194.         ParmD   dst_offset          ; offset to start at
  195.         ParmD   dst_next_scan       ; dst_next_scan.
  196.         ParmD   src_ptr             ; --> src.
  197.         ParmD   src_offset          ; offset to start at
  198.         ParmD   src_next_scan       ; dst_next_scan.
  199.         ParmD   pel_count           ; pixel count.
  200.         ParmD   scan_count          ; scan count.
  201.         ParmD   xlat_table          ; pixel convert table.
  202. cBegin
  203.         xor     esi,esi
  204.         xor     edi,edi
  205.         xor     ebx,ebx
  206.         lfs     si,src_ptr
  207.         les     di,dst_ptr
  208.         lds     bx,xlat_table
  209.  
  210.         add     esi,src_offset
  211.         add     edi,dst_offset
  212.  
  213.         mov     eax,pel_count
  214.         sub     src_next_scan,eax
  215.         sub     dst_next_scan,eax
  216.  
  217.     mov    edx,pel_count
  218.     xor    ebx,ebx
  219. align 4
  220. convert_8_8_start:
  221.     mov    ecx,edx ;pel_count
  222.     shr    ecx,2
  223.         jz      short convert_8_8_ack
  224. align 4
  225. convert_8_8_loop:
  226.         mov     eax,fs:[esi]        ; grab 4 pixels
  227.  
  228.     mov    bl,al            ; get pel
  229.     mov    al,[ebx]        ; translate pel
  230.     mov    bl,ah            ; get pel
  231.     mov    ah,[ebx]        ; translate pel
  232.  
  233.         rol     eax,16
  234.  
  235.     mov    bl,al            ; get pel
  236.     mov    al,[ebx]        ; translate pel
  237.     mov    bl,ah            ; get pel
  238.     mov    ah,[ebx]        ; translate pel
  239.  
  240.         rol     eax,16
  241.         mov     es:[edi],eax        ; store four
  242.  
  243.         add     esi,4
  244.         add     edi,4
  245.     dec    ecx
  246.     jnz    short convert_8_8_loop
  247.  
  248. convert_8_8_ack:
  249.     mov    ecx,edx ;pel_count
  250.     and    ecx,3
  251.     jnz    short convert_8_8_odd
  252.  
  253. convert_8_8_next:
  254.     nxtscan si,src_next_scan
  255.         nxtscan di,dst_next_scan
  256.  
  257.         dec     scan_count
  258.         jnz     short convert_8_8_start
  259. cEnd
  260.  
  261. convert_8_8_odd:
  262. @@:    mov    bl,fs:[esi]
  263.     mov    bl,[ebx]
  264.         mov     es:[edi],bl
  265.         inc     esi
  266.         inc     edi
  267.     dec    ecx
  268.     jnz    short convert_8_8_odd
  269.         jz      short convert_8_8_next
  270.  
  271. endif
  272.  
  273.  
  274. sEnd    CodeSeg
  275.  
  276. end
  277.  
  278. COMMENT |
  279.  
  280. Todd's old code:
  281.  
  282. align 4
  283. convert_8_8_start:
  284.     mov    ecx,edx ;pel_count
  285.     shr    ecx,2
  286.         jz      short convert_8_8_ack
  287. align 4
  288. convert_8_8_loop:
  289.         mov     eax,fs:[esi]        ; grab 4 pixels
  290.  
  291.     mov    bl,al            ; get pel
  292.     mov    al,[ebx]        ; translate pel
  293.     mov    bl,ah            ; get pel
  294.     mov    ah,[ebx]        ; translate pel
  295.  
  296.         rol     eax,16
  297.  
  298.     mov    bl,al            ; get pel
  299.     mov    al,[ebx]        ; translate pel
  300.     mov    bl,ah            ; get pel
  301.     mov    ah,[ebx]        ; translate pel
  302.  
  303.         rol     eax,16
  304.         mov     es:[edi],eax        ; store four
  305.  
  306.         add     esi,4
  307.         add     edi,4
  308.     dec    ecx
  309.     jnz    short convert_8_8_loop
  310.  
  311. convert_8_8_ack:
  312.     mov    ecx,edx ;pel_count
  313.     and    ecx,3
  314.     jnz    short convert_8_8_odd
  315.  
  316. convert_8_8_next:
  317.     nxtscan si,src_next_scan
  318.         nxtscan di,dst_next_scan
  319.  
  320.         dec     scan_count
  321.         jnz     short convert_8_8_start
  322.  
  323. My third try:
  324.  
  325. convert_8_8_start:
  326.  
  327.     mov    ecx,pel_count
  328.     shr    ecx,2
  329.     jz    short convert_8_8_ack
  330.  
  331.     shr    ecx,1
  332.     jc    fixup_for_halfway
  333.  
  334. align 4
  335.  
  336. convert_8_8_loop:
  337.  
  338.     mov    eax,fs:[esi]        ; grab 4 pixels
  339.  
  340.     mov    bl,al            ; get pel
  341.     mov    dl,ah            ; get pel
  342.     mov    al,[ebx]        ; translate pel
  343.     mov    ah,[edx]        ; translate pel
  344.  
  345.     rol    eax,16
  346.  
  347.     mov    bl,al            ; get pel
  348.     mov    dl,ah            ; get pel
  349.     mov    al,[ebx]        ; translate pel
  350.     mov    ah,[edx]        ; translate pel
  351.  
  352.     rol    eax,16
  353.  
  354.     mov    es:[edi],eax        ; store four
  355.  
  356. half_way:
  357.     mov    eax,fs:[esi+4]        ; grab 4 pixels
  358.  
  359.     mov    bl,al            ; get pel
  360.     mov    dl,ah            ; get pel
  361.     mov    al,[ebx]        ; translate pel
  362.     mov    ah,[edx]        ; translate pel
  363.  
  364.     rol    eax,16
  365.  
  366.     mov    bl,al            ; get pel
  367.     mov    dl,ah            ; get pel
  368.     mov    al,[ebx]        ; translate pel
  369.     mov    ah,[edx]        ; translate pel
  370.  
  371.     rol    eax,16
  372.  
  373.     mov    es:[edi+4],eax        ; store four
  374.  
  375.     add    esi,8
  376.     add    edi,8
  377.  
  378.     dec    ecx
  379.     jnz    short convert_8_8_loop
  380.  
  381. convert_8_8_ack:
  382.     mov    ecx,pel_count
  383.     and    ecx,3
  384.     jnz    short convert_8_8_odd
  385.  
  386. convert_8_8_next:
  387.     nxtscan si,src_next_scan
  388.     nxtscan di,dst_next_scan
  389.  
  390.     dec    scan_count
  391.     jnz    short convert_8_8_start
  392. cEnd
  393.  
  394. fixup_for_halfway:
  395.     sub    edi,4
  396.     sub    esi,4
  397.     jmp    half_way
  398.  
  399. convert_8_8_odd:
  400. @@:    mov    bl,fs:[esi]
  401.     mov    bl,[ebx]
  402.     mov    es:[edi],bl
  403.     inc    esi
  404.     inc    edi
  405.     dec    ecx
  406.     jnz    short convert_8_8_odd
  407.     jz    short convert_8_8_next
  408.  
  409. -----
  410.  
  411.         xor     esi,esi
  412.         xor     edi,edi
  413.         xor     ebx,ebx
  414.         xor    edx,edx
  415.  
  416.         lfs     si,src_ptr
  417.         les     di,dst_ptr
  418.         lds     bx,xlat_table
  419.  
  420.         add     esi,src_offset
  421.         add     edi,dst_offset
  422.  
  423.         mov     eax,pel_count
  424.         sub     src_next_scan,eax
  425.         sub     dst_next_scan,eax
  426.  
  427. align 4
  428. convert_8_8_start:
  429.  
  430.     mov    ecx,pel_count
  431.     shr    ecx,2
  432.     jz    short convert_8_8_ack
  433.  
  434. align 4
  435.  
  436. convert_8_8_loop:
  437.  
  438.     mov    eax,fs:[esi+2]        ; grab 2 pixels
  439.  
  440.     mov    bl,al            ; get pel
  441.     mov    dl,ah            ; get pel
  442.     mov    al,[ebx]        ; translate pel
  443.     mov    ah,[edx]        ; translate pel
  444.  
  445.     shl    eax,16
  446.  
  447.     mov    ax,fs:[esi]        ; grab 2 more
  448.  
  449.     mov    bl,al            ; get pel
  450.     mov    dl,ah            ; get pel
  451.     mov    al,[ebx]        ; translate pel
  452.     mov    ah,[edx]        ; translate pel
  453.  
  454.     mov    es:[edi],eax        ; store four
  455.  
  456.     add    esi,4
  457.     add    edi,4
  458.  
  459.     dec    ecx
  460.     jnz    short convert_8_8_loop
  461.  
  462. convert_8_8_ack:
  463.     mov    ecx,pel_count
  464.     and    ecx,3
  465.     jnz    short convert_8_8_odd
  466.  
  467. convert_8_8_next:
  468.     nxtscan si,src_next_scan
  469.     nxtscan di,dst_next_scan
  470.  
  471.     dec    scan_count
  472.     jnz    short convert_8_8_start
  473. cEnd
  474.  
  475. convert_8_8_odd:
  476. @@:    mov    bl,fs:[esi]
  477.     mov    bl,[ebx]
  478.     mov    es:[edi],bl
  479.     inc    esi
  480.     inc    edi
  481.     dec    ecx
  482.     jnz    short convert_8_8_odd
  483.     jz    short convert_8_8_next
  484.  
  485.  
  486. ENDCOMMENT |
  487.